{# SPDX-License-Identifier: Apache-2.0 -#}

{% extends "admin/base.html" %}

{% import "admin/utils/pagination.html" as pagination %}

{% block title %}Prohibited Project Names{% endblock %}

{% block breadcrumb %}
  <li class="breadcrumb-item">Prohibition Era</li>
  <li class="breadcrumb-item active">Project Names</li>
{% endblock %}

{% block content %}
<div class="card">
  <div class="card-body">
    <form>
      <div class="input-group input-group-lg">
        <input name="q" type="text" class="form-control input-lg" placeholder="Search"{% if query %} value="{{ query }}"{% endif %}>
        <div class="input-group-btn input-group-append">
          <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
        </div>
      </div>
    </form>
  </div>
</div>

<div class="card">
  <div class="card-body table-responsive p-0">
    <table class="table table-hover table-striped">
      <thead>
      <tr>
        <th>Name</th>
        <th>Prohibited by</th>
        <th>Prohibited on</th>
        <th>Comment</th>
        <th>Observation kind</th>
        <th>Actions</th>
      </tr>
      </thead>

      <tbody>
      {% for prohibited_project_name in prohibited_project_names %}
      <tr>
        <td>{{ prohibited_project_name.name }}</td>
        <td>
          {% if prohibited_project_name.prohibited_by %}
            <a href="{{ request.route_path('admin.user.detail', username=prohibited_project_name.prohibited_by.username) }}">
              {{ prohibited_project_name.prohibited_by.username }}
            </a>
          {% endif %}
        </td>
        <td>{{ prohibited_project_name.created|format_datetime() }}</td>
        <td>{{ prohibited_project_name.comment }}</td>
        <td>{{ prohibited_project_name.observation_kind }}</td>
        <td>
          <form method="POST" action="{{ request.route_path('admin.prohibited_project_names.remove') }}">
            <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
            <input name="prohibited_project_name_id" type="hidden" value="{{ prohibited_project_name.id }}">
            <input name="next" type="hidden" value="{{ request.current_route_path() }}">
            <button type="submit" class="btn btn-link" title="{{ 'Submitting requires superuser privileges' if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}>
              <i class="fa fa-times"></i>
            </button>
          </form>
          <form method="POST" action="{{ request.route_path('admin.prohibited_project_names.release') }}">
            <input name="csrf_token" type="hidden" value="{{ request.session.get_csrf_token() }}">
            <input name="project_name" type="hidden" value="{{ prohibited_project_name.name }}">
            <input name="next" type="hidden" value="{{ request.current_route_path() }}">
            <button type="submit" class="btn btn-link" title="{{ 'Submitting requires additional privileges' if not request.has_permission(Permissions.AdminProhibitedProjectsRelease) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsRelease) }}>
              <i class="fa fa-hands"></i>
            </button>
            <input name="username" type="text" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsRelease) }}>
          </form>
        </td>
      </tr>
      {% endfor %}
      </tbody>
    </table>

    <div class="card-footer">
      <div class="col-sm-5">
          {{ pagination.summary(prohibited_project_names) }}
      </div>

      <div class="col-sm-7">
        <div class="float-right">
            {{ pagination.paginate(prohibited_project_names) }}
        </div>
      </div>
    </div>

  </div>
</div>

<div class="card card-primary">
  <div class="card-header">
    <h3 class="card-title">Prohibit project name</h3>
  </div>

  <form method="GET" action="{{ request.route_path('admin.prohibited_project_names.add') }}">
    <div class="card-body">
      <div class="form-group col-sm-4">
        <label for="prohibitedProjectName">Project name</label>
        <input name="project" class="form-control" id="prohibitedProjectName" placeholder="Enter project name to prohibit " {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }} autocomplete="off" autocorrect="off" autocapitalize="off">
      </div>

      <div class="form-group col-sm-8">
        <label for="prohibitedComment">Comment</label>
        <textarea name="comment" class="form-control" id="prohibitedComment" rows="3" placeholder="Enter comment ..." {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}></textarea>
      </div>
    </div>


    <div class="card-footer">
      <div class="float-right">
        <button type="submit" class="btn btn-primary" title="{{ 'Submitting requires superuser privileges' if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}" {{ "disabled" if not request.has_permission(Permissions.AdminProhibitedProjectsWrite) }}>Submit</button>
      </div>
    </div>
  </form>
</div>
{% endblock content %}
